<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>basics_setting</title>
    <link rel="stylesheet" href="../../../static/layer/css/layui.css" media="all"/>
    <link rel="stylesheet" href="../../../static/css/font-awesome.min.css" media="all">
    <style>
        .layui-form-switch {
            width: 54px;
            margin-top: 0;
        }
        .layui-form-switch i{
            top: 2px;
        }
    </style>
</head>

<body>
<div style="padding: 20px; position: relative;">
    <!--<div class="layui-btn-group operateTable">
        <button class="layui-btn" data-type="getCheckData">获取选中行数据</button>
        <button class="layui-btn" data-type="getCheckLength">获取选中数目</button>
        <button class="layui-btn" data-type="isAll">验证是否全选</button>
    </div>-->
    <div class="operateTable layui-form">
        名称：
        <div class="layui-inline">
            <input class="layui-input" name="id" id="filter-id" placeholder="请输入关键字" autocomplete="off">
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <select name="type-name" lay-verify="type-name" lay-search="">
                    <option value="">直接选择或搜索选择</option>
                    <option value="所属行业">所属行业</option>
                    <!--<option value="项目类型">项目类型</option>-->
                    <option value="退租原因">退租原因</option>
                </select>
            </div>
        </div>
        <button class="layui-btn" data-type="reload">搜索</button>
    </div>
    <div class="operateTable" style="position: absolute; top: 20px; right: 20px;">
        <button class="layui-btn AUTH-JCSZ_XZ" data-type="addDictionary"><i class="layui-icon"></i> 新增数据</button>
    </div>
    <table class="layui-table" lay-data="{height:'full-80', url:'/dictionary/json/', page:true, limit:20, id:'dictionaryTable'}"
           lay-filter="dictionary">
        <thead>
        <tr>
            <!--<th lay-data="{checkbox:true, fixed: true}"></th>-->
            <th lay-data="{field:'ROWNUM', fixed: true}"></th>
            <!--<th lay-data="{field:'CODE', width:120}">类型编码</th>-->
            <th lay-data="{field:'PNAME', width:200}">类型名称</th>
            <th lay-data="{field:'NAME', width:300}">名称</th>
            <th lay-data="{field:'SORT', width:150}">排序</th>
            <th lay-data="{field:'CREATE_NAME', width:200}">创建人</th>
            <th lay-data="{field:'CREATE_DATE', width:250, align:'center'}">创建时间</th>
            <th lay-data="{fixed: 'right', width:250, align:'center', toolbar: '#barDemo'}">操作</th>
        </tr>
        </thead>
    </table>
    <div style="display: none;" id="barDemo">
        <a class="layui-btn layui-btn-primary layui-btn-mini AUTH-JCSZ_CK" lay-event="detail">查看</a>
        <a class="layui-btn layui-btn-mini AUTH-JCSZ_BJ" lay-event="edit">编辑</a>
        {{# if(d.CREATE_ID=== ''){ }}
        {{# } else{ }}
        <a class="layui-btn layui-btn-danger layui-btn-mini AUTH-JCSZ_SC" lay-event="del">删除</a>
        {{# } }}
    </div>
   <!-- <script type="text/html" id="barDemo">

    </script>-->
</div>
<script type="text/javascript" src="../../../static/layer/layui.js"></script>
<script>
    var table;
    layui.use(['jquery', 'table', 'form', 'layer'], function () {
        table = layui.table;
        var form = layui.form;
        //监听表格复选框选择
        table.on('checkbox(dictionary)', function (obj) {
            console.log(obj)
        });
        //监听工具条
        table.on('tool(dictionary)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.open({
                    type: 2,
                    title: "【" + data.PNAME + "】" + data.NAME,
                    shadeClose: false,
                    shade: [0.3],
                    maxmin: true, //开启最大化最小化按钮
                    area: ['900px', '90%'],
                    scrollbar: false, //屏蔽滚动条
                    content: 'operate.html?type=view&id=' + data.ID
                });
            } else if (obj.event === 'del') {
                layer.confirm('确认删除【'+data.PNAME+'】' + data.NAME + '吗', {offset: '150px'}, function (index) {
//                    obj.del();
                    layer.close(index);
                    $.ajax({
                        url: "/dictionary/edit",
                        data: {ID: data.ID, IS_DEL: 1},
                        dataType: "json",
                        type: "post",
                        async: false,
                        success: function (res) {
                            if (res.errcode === "0"){
                                reload();    // 表格刷新
                                layer.msg("【" + data.PNAME + "】" + data.NAME + " 已删除", {offset: '150px'});   // 弹出删除成功
                            } else if (res.errcode === "1"){
                                layer.msg(res.errmsg, function(){});
                            }
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown) {
                            console.error(XMLHttpRequest.status);
                            console.error(XMLHttpRequest.readyState);
                            console.error(textStatus);
                        }
                    });
                });
            } else if (obj.event === 'edit') {
                layer.open({
                    type: 2,
                    title: "编辑【" + data.PNAME + "】" + data.NAME,
                    shadeClose: false,
                    shade: [0.3],
                    maxmin: true, //开启最大化最小化按钮
                    area: ['900px', '90%'],
                    scrollbar: false, //屏蔽滚动条
                    content: 'operate.html?type=edit&id=' + data.ID
                });
            }
        });

        var $ = layui.$, active = {
            getCheckData: function () { //获取选中数据
                var checkStatus = table.checkStatus('dictionaryTable')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
            , getCheckLength: function () { //获取选中数目
                var checkStatus = table.checkStatus('dictionaryTable')
                    , data = checkStatus.data;
                layer.msg('选中了：' + data.length + ' 个');
            }
            , isAll: function () { //验证是否全选
                var checkStatus = table.checkStatus('dictionaryTable');
                layer.msg(checkStatus.isAll ? '全选' : '未全选')
            }
            , reload: function () {
                var name = $('#filter-id').val();
                var typeName = $('select[name="type-name"]').val();
                table.reload('dictionaryTable', {
                    where: {
                        KEYNAME: name,
                        PNAME: typeName
                    }
                });
            }
            , addDictionary: function () {
                layer.open({
                    type: 2,
                    title: '新增数据',
                    shadeClose: false,
                    shade: [0.3],
                    maxmin: true, //开启最大化最小化按钮
                    area: ['900px', '90%'],
                    scrollbar: false, //屏蔽滚动条
                    content: 'operate.html?type=add'
                });
            }
        };

        // 初始化下拉框
        $.ajax({
            url: "/dictionary/listPname",
            data: {},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0"){
                    var data = res.data;
                    if (!!data) {
                        for (var i = 0; i < data.length; i++) {
                            var str = '<option value="' + data[i].PNAME + '">' + data[i].PNAME + '</option>\n';
                            if (data[i].CODE != "PRO_007" && data[i].CODE != "PRO_009" && data[i].CODE != "PRO_010") {
                                $("select[name='type-name']").append(str);
                            }
                        }
                        form.render("select");
                    }

                } else if (res.errcode === "1"){
                    layer.msg(res.errmsg, function(){});
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });

        $('.operateTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

    function reload() {
        table.reload('dictionaryTable', {});
    }
</script>
<script type="text/javascript" src="../../../static/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../../../static/js/common/authUtils.js"></script>
</body>

</html>